package com.xjtu.platform.security.register.imply;

import com.xjtu.platform.security.register.RegisterDto;
import com.xjtu.platform.security.register.RegisterService;
import com.xjtu.platform.security.register.dao.RegisterDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Transactional
public class RegisterServiceImpl implements RegisterService {

    @Resource
    private RegisterDao registerDao;

    @Override
    public boolean insertUser(RegisterDto registerDto,String role) {
        try {
            registerDao.insertUser(registerDto,role);
            int count = registerDao.getCount() + 1;
            registerDao.insertRole(registerDto,role,count);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public String getRole(RegisterDto registerDto) {
        try {
            String role = registerDao.getRole(registerDto);
            return role;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
